<?php

	/*
	*	进行信息检查的工具类
	*/

	class Check {
		
		private $resumeInfo;
		
		public function __construct() {
			
			$this->resumeInfo = $_POST;
			
		}
		
		
		//	检查姓名
		public function checkName() {
			
			$name = $this->resumeInfo['name'];
			
			if(mb_strlen($name, 'utf-8') >= 10) {
				
				return false;
				
			}
			
			return true;
		}

		
		//	检查邮箱信息
		public function checkMail() {
			
			$p_email = $this->resumeInfo['personMail'];							//	第一次填写的邮箱
	
			$c_email = $this->resumeInfo['companyMail'];						//	第二次填写的邮箱
			
			$email_pattern = "/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/";	//	正则串
			
			if(0 != strcmp($p_email, $c_email)) {
				
				return false;
			
			}
			
			if(1 != preg_match($email_pattern, $p_email)) {
		
				return false;
		
			}
			
			return true;
		}
		
		
		//	检查电话号码
		public function checkTell() {
			
			$tell = $this->resumeInfo['tell'];
			
			$tell_pattern = "/^1[34578]\d{9}$/";;
			
			if(strlen($tell) != 11) {
				
				return false;
				
			}
			
			if(1 != preg_match($tell_pattern, $tell)) {
				
				return false;
				
			}
			
			return true;
			
		}
		
		
		//	检查学校和专业信息
		public function checkSchool() {
			
			$school = $this->resumeInfo['school'];
			$major = $this->resumeInfo['major'];
			
			if(mb_strlen($school, 'utf-8') >= 30) {
				return false;
			}
			
			if(mb_strlen($major, 'utf-8') >= 30) {
				return false;
			}
			
			return true;
		}
		
		
		//	检查附件
		public function checkFile($fileName) {
			
			$format = substr($fileName, -4);			//	附件格式
				
			$annex_dir = 'D:\PHP\PHPTutorial\WWW\UXIN\resume\resume_annex\\';
				
			$file = $annex_dir.$_FILES['resume_annex']['name'];
				
			if(!($format != '.pdf' || $format != '.PDF')) {
				
				return false;
				
			}
			
			if(file_exists($file)) {
				
				return false;
				
			}
				
			if($_FILES['resume_annex']['size'] > 4*1024*1024) {
				
				return false;
				
			}
				
			move_uploaded_file($_FILES['resume_annex']['tmp_name'],
								$annex_dir.iconv('UTF-8', 'gb2312',
								$_FILES['resume_annex']['name']));
				
			$this->resumeInfo['has_annex'] = 1;
			
			return true;
		}
	}
	
?>